package com.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateUtil {





    public static final String fm1 = "yyyy-MM-dd";
    public static final String fm2 = "yyyy-MM-dd HH:mm:ss";
    public static final String fm3 = "yyyy-MM-dd HH:mm:ss EE";
    public static final String fm4 = "yyyy-MM-dd HH:mm:ss zzz";
    public static final String fm5 = "dow mon dd HH:mm:ss zzz yyyy";
    public static final String fm6 = "yyyy-MM-dd hh:mm:ss";  //不建议使用12小时制
    public static final String fm7 = "hh:mm:ss";  //只要时分秒





    //日期处理类

    public static String parseTime(String datdString) {
        datdString = datdString.replace("GMT", "").replaceAll("\\(.*\\)", "");
        //将字符串转化为date类型，格式
        SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss z", Locale.ENGLISH);
        Date dateTrans = null;
        try {
            dateTrans = format.parse(datdString);
//                        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateTrans).replace("-","/");
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateTrans);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return datdString;

    }


    public static Date parseDateTime(String dateString) {
        //将字符串转化为date类型，格式
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        Date dateTrans = null;
        try {
            // 注意格式需要与上面一致，不然会出现异常
            dateTrans = format.parse(dateString);
            return dateTrans;

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;

    }

    //日期转成指定格式的字符串
    public static String parseDateToString(Date date, String pattern){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        String dateTrans = simpleDateFormat.format(date);
        return dateTrans;

    }





}
